package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Fxz
 * @version 1.0
 * @date 2022-02-06 18:50
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/admin/product")
@RequiredArgsConstructor
public class SkuManageController {

	private final ManageService manageService;

	/**
	 * 保存skuInfo
	 */
	@PostMapping("/saveSkuInfo")
	public Result saveSkuInfo(@RequestBody SkuInfo skuInfo) {
		return Result.ok(manageService.saveSkuInfo(skuInfo));
	}

	/**
	 * 分页查询skuInfo
	 */
	@GetMapping("/list/{page}/{limit}")
	public Result getSkuInfoList(@PathVariable Long page, @PathVariable Long limit) {
		return Result.ok(manageService.getSkuInfoList(new Page<SkuInfo>(page, limit)));
	}

	/**
	 * 商品上架
	 */
	@GetMapping("/onSale/{skuId}")
	public Result onSale(@PathVariable Long skuId) {
		return Result.ok(manageService.onSale(skuId));
	}

	/**
	 * 商品下架
	 */
	@GetMapping("/cancelSale/{skuId}")
	public Result cancelSale(@PathVariable Long skuId) {
		return Result.ok(manageService.cancelSale(skuId));
	}

}
